import React from 'react'

// 导入样式文件
import './index.css'

export default class App extends React.Component {
  state = {
    comments: [
      { id: 1, name: '亚瑟', content: '沙发！！！' },
      { id: 2, name: '妲己', content: '板凳~' },
      { id: 3, name: '程咬金', content: '楼主好人' }
    ]
  }

  renderList = () => {
    if (this.state.comments.length === 0) {
      return (<div className="no-comment">暂无评论，快去评论吧~</div>)
    }

    return (
      <ul>
        {
          this.state.comments.map(item => (
            <li key={item.id}>
              <h3>评论人：{item.name}</h3>
              <p>评论内容：{item.content}</p>
            </li>
          ))
        }
      </ul>
    )
  }

  render() {
    return (
      <div className="app">
        <div>
          <input className="user" type="text" placeholder="请输入评论人" />
          <br />
          <textarea
            className="content"
            cols="30"
            rows="10"
            placeholder="请输入评论内容"
          />
          <br />
          <button>发表评论</button>
        </div>

        {/* 评论区域 */}
        { this.renderList() }
      </div>
    )
  }
}